package com.espirit.builder.biz;

import org.springframework.stereotype.Component;

import com.espirit.common.Message;
import com.espirit.eap.manager.MessageViewType;
import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.pagelayout.SectionElement;
import com.googlecode.cswish.annotation.Dependence;


@Dependence({
	"com.espirit.builder.biz.WFInstanceBuilder"
})
@Component
public class MessageBuilder extends ModelBuilderSupport {
	protected static final String FIELD_FROM="from";
	protected static final String FIELD_TO="to";
	protected static final String FIELD_TITLE = "title";
	protected static final String FIELD_CREATEDON ="initDate";
	protected static final String FIELD_PHASE = "instance.wfPhase";
	protected static final String FIELD_TEMPLATE = "instance.wfTemplate";
	protected static final String FIELD_PHASEDESCRIPTION = "instance.description";
	protected static final String FIELD_WFSTATUS ="status";
	protected static final String FIELD_DESCRIPTION = "description";
	protected static final String FIELD_INSTANCE ="instance";
	protected static final String FIELD_MESSAGEVIEWTYPE ="messageViewType";
	
	
	@Override
	public boolean init() {
		return super.setClass(Message.class, "Message", "消息") ;
	}
	
	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(FIELD_FROM,"From","发起者");
		addModelField(FIELD_TITLE,"Title","标题");
		addModelField(FIELD_PHASE,"Current Phase","当前环节");
		addModelField(FIELD_TEMPLATE,"Workflow Template","审批模板");
		addModelField(FIELD_CREATEDON,"Created On","发起时间");
		addModelField(FIELD_DESCRIPTION,"Description","备注");
		addModelField(FIELD_TO,"To","接收人");
		addModelField(FIELD_MESSAGEVIEWTYPE,"Status","状态");
	}
	
	@Override
	public void prepareLayoutElements() {
		ModelField mfFrom = getModelField(FIELD_FROM);
		ModelField mfTo = getModelField(FIELD_TO);
		ModelField mfTitle = getModelField(FIELD_TITLE);
		ModelField mfPhase = getModelField(FIELD_PHASE);
		ModelField mfCreatedOn = getModelField(FIELD_CREATEDON);
		ModelField mfDescription = getModelField(FIELD_DESCRIPTION);
		
		ModelField mfStatus = getModelField(FIELD_MESSAGEVIEWTYPE);
		mfStatus.setGenericType(MessageViewType.class.getName());

		addSearchField(mfTitle,mfStatus);
		addListField(mfFrom,mfTitle,mfPhase,mfCreatedOn,mfDescription);
		addDetailField(mfTitle,mfTo,mfDescription);
		super.prepareLayoutElements();
	}
	
	@Override
	protected Integer getDetailLayoutSectionColsPerRow() {
		return 1;
	}
	
	@Override
	protected void afterBuilderLayout() {
		SectionElement description = model.getDefaultDetailLayout().findSectionElement(FIELD_DESCRIPTION);
		description.setTagName("textarea");
		super.afterBuilderLayout();
	}
	
	

}
